package oop.basicConcept;

public class MyTime {

    int hour;
    int minute;
    int second;

    public MyTime(){
        this.hour = 0;
        this.minute = 0;
        this.second = 0;
    }

    public MyTime(int hour,int minute,int second){
        this.hour = hour;
        this.minute = minute;
        this.second = second;
    }

    public void display(){
        System.out.println(hour+":"+minute+":"+second);
    }

    public void addHour(int hour){
        this.hour += hour;
        if(this.hour >=24){
            this.hour %= 24;
        }
    }

    public void addMinute(int minute){
        this.minute += minute;
        if(this.minute>=60){
            this.addHour(this.minute/60);
            this.minute %= 60;
        }
    }

    public void addSecond(int second){
        this.second += second;
        if(this.second >= 60){
            this.addMinute(this.second/60);
            this.second %= 60;
        }
    }

    public void subHour(int hour){
        this.hour -= hour;
        if(this.hour<0){
            this.hour = 0;
        }
    }

    public void subMinute(int minute){
        this.minute -= minute;
        if(this.minute<0){
            this.subHour(this.minute/60);
            this.minute %= 60;
        }
    }

    public void subSecond(int second){
        this.second -= second;
        if(this.second<0){
            this.subMinute((second-this.second)/60);
            this.second %= 60;
        }
    }

    public static void main(String[] args) {
        MyTime myTime = new MyTime(23,59,59);

        myTime.subSecond(120);

        myTime.display();

    }

}
